package com.waa.gulimall.product.app;

import java.util.Arrays;
import java.util.Map;

import com.waa.gulimall.common.validator.group.AddGroup;
import com.waa.gulimall.common.validator.group.UpdateGroup;
import com.waa.gulimall.common.validator.group.UpdateStatusGroup;
import com.waa.gulimall.product.feign.MemberFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.waa.gulimall.product.entity.BrandEntity;
import com.waa.gulimall.product.service.BrandService;
import com.waa.gulimall.common.utils.PageUtils;
import com.waa.gulimall.common.utils.R;


/**
 * 品牌
 *
 * @author waa
 * @email 2460335742@qq.com
 * @date 2022-02-22 09:57:25
 */
@RestController
@RequestMapping("product/brand")
@RefreshScope//刷新nacos配置
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @Value("${product.user.name}")
    private  String name;
    @Autowired
    private MemberFeignService memberFeignService;
    @RequestMapping("/test")
    public R test(){
        BrandEntity brandEntity = new BrandEntity();
        brandEntity.setName(name);
        R memberlist = memberFeignService.memberlist();
        return R.ok().put("brandEntity:",brandEntity).put("member:",memberlist);
    }
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = brandService.queryPage(params);
        return R.ok().put("page", page);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);
        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@Validated(AddGroup.class) @RequestBody BrandEntity brand){
            brandService.save(brand);
            return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@Validated(value = {UpdateGroup.class}) @RequestBody BrandEntity brand){
		brandService.updateDetail(brand);
        return R.ok();
    }
    @RequestMapping("/update/status")
    public R updatestatus(@Validated(value = {UpdateStatusGroup.class}) @RequestBody BrandEntity brand){
        brandService.updateById(brand);
        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));

        return R.ok();
    }

}
